package com.wcpdoc.base.service.impl;

import com.wcpdoc.base.dao.LogDao;
import com.wcpdoc.base.entity.OpLog;
import com.wcpdoc.base.service.OpLogService;
import com.wcpdoc.core.dao.BaseDao;
import com.wcpdoc.core.service.impl.BaseServiceImp;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;

@Service
public class OpLogServiceImpl extends BaseServiceImp<OpLog> implements OpLogService {
    private static final Logger log = LoggerFactory.getLogger(OpLogServiceImpl.class);
    @Resource
    private LogDao logDao;

    @Override
    @Resource(name = "logDaoImpl")
    public void setDao(BaseDao<OpLog> dao) {
        super.dao = dao;
    }
    /**
     * 记录日志
     *
     * @param userId
     * @param logType
     */
    @Override
    public void log(Integer userId, Integer logType) {
        try {
            OpLog log = new OpLog();
            log.setUserId(userId);
            log.setOpType(logType);
            log.setUpdateTime(new Date());
            logDao.add(log);
        }
        catch (Exception e) {
            log.error("记录日志失败", e);
        }
    }
}
